extends ../layout

block content
  .container.artlist-box
    .row
      table.table.table-hover.table-bordered
        thead
          tr
            th 类别
            th 文章标题
            th 摘要
            //- th 正文
            th 查看
            th 删除
            //- th 群发
        tbody
          each item in articles
            tr(class="item-id-#{item._id}")
              td 
                if item.category
                  | #{item.category.name}
              td #{item.title}
              td #{item.abstract}
              //- td #{item.meta.text}
              td: a(target="_blank", href="/admin/article/one/#{item._id}") 查看
              td
                button.btn.btn-danger.del(type="button", data-id="#{item._id}") 删除
              //- td
              //-   if !item.isSend
              //-     button.btn.btn-danger.sendAll(type="button", data-id="#{item._id}") 群发
  script.
    $(function(){
      $('.del').click(function(e) {
        var target = $(e.target)
        var id = target.data('id')
        var tr = $('.item-id-' + id)

        $.ajax({
          type: 'DELETE',
          url: '/admin/movie/list?id=' + id
        })
        .done(function(results) {
          if (results.success === 1) {
            if (tr.length > 0) {
              tr.remove()
            }
          }
        })
      })
      $('.sendAll').click(function(e) {
        var target = $(e.target)
        var id = target.data('id')
        var tr = $('.item-id-' + id)

        $.ajax({
          type: 'post',
          url: '/admin/article/sendAll?id=' + id
        })
        .done(function(results) {
          if (results) {
            alert('发送成功')
          }
        })
      })
    })